package com.chenxin.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenxin.common.annotation.Log;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.enums.BusinessType;
import com.chenxin.wms.domain.CustomerEntity;
import com.chenxin.wms.service.ICustomerService;
import com.chenxin.common.utils.poi.ExcelUtil;
import com.chenxin.common.core.page.TableDataInfo;

/**
 * 客户资料Controller
 *
 * @author gry
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/wms/customer")
public class CustomerController extends BaseController {
    @Autowired
    private ICustomerService customerService;

    /**
     * 查询客户资料列表
     */
    @PreAuthorize("@ss.hasPermi('wms:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerEntity customerEntity) {
        startPage();
        List<CustomerEntity> list = customerService.selectCustomerList(customerEntity);
        return getDataTable(list);
    }

    /**
     * 导出客户资料列表
     */
    @PreAuthorize("@ss.hasPermi('wms:customer:export')")
    @Log(title = "客户资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerEntity customerEntity) {
        List<CustomerEntity> list = customerService.selectCustomerList(customerEntity);
        ExcelUtil<CustomerEntity> util = new ExcelUtil<CustomerEntity>(CustomerEntity.class);
        util.exportExcel(response, list, "客户资料数据");
    }

    /**
     * 获取客户资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:customer:query')")
    @GetMapping(value = {"/", "/{customerId}"})
    public AjaxResult getInfo(@PathVariable(value = "customerId", required = false) Long customerId) {
        return success(customerService.selectCustomerByCustomerId(customerId));
    }

    /**
     * 新增客户资料
     */
    @PreAuthorize("@ss.hasPermi('wms:customer:add')")
    @Log(title = "客户资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerEntity customerEntity) {
        return toAjax(customerService.insertCustomer(customerEntity));
    }

    /**
     * 修改客户资料
     */
    @PreAuthorize("@ss.hasPermi('wms:customer:edit')")
    @Log(title = "客户资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerEntity customerEntity) {
        return toAjax(customerService.updateCustomer(customerEntity));
    }

    /**
     * 删除客户资料
     */
    @PreAuthorize("@ss.hasPermi('wms:customer:remove')")
    @Log(title = "客户资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds) {
        return toAjax(customerService.deleteCustomerByCustomerIds(customerIds));
    }
}
